package lesson.ch12;

import java.io.File;
import java.io.IOException;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;
import org.springframework.stereotype.Component;

@Component("pdfReader")
public class PdfReader implements IContentReader {
    public String readContent(String url) {        
        try {
            PDDocument  document = PDDocument.load(new File(url));
            PDFTextStripper stripper = new PDFTextStripper();
            stripper.setStartPage(0);
            stripper.setEndPage(document.getNumberOfPages());
            return stripper.getText(document);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

}
